﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Script.Commands;
using DSS_XNA.Engine.Script.Functions;

namespace DSS_XNA.Engine.Script
{
    public static class ScriptCommands
    {
        #region Properties

        public static Dictionary<string, ScriptCommand.ScriptCommandActionDelegate> AvaliableCommands
        {
            get
            {
                if (_avaliableCommands == null)
                {
                    BuildAvaliableCommands();
                }

                return _avaliableCommands;
            }
            set { ScriptCommands._avaliableCommands = value; }
        }
        private static Dictionary<string, ScriptCommand.ScriptCommandActionDelegate> _avaliableCommands = null;

        public static Dictionary<string, ScriptCommand.ScriptBuildInFunctionActionDelegate> AvaliableBuildInFunctions
        {
            get
            {
                if (_avaliableBuildInFunctions == null)
                {
                    BuildAvaliableBuildInFunctions();
                }

                return _avaliableBuildInFunctions;
            }
            set { ScriptCommands._avaliableBuildInFunctions = value; }
        }
        private static Dictionary<string, ScriptCommand.ScriptBuildInFunctionActionDelegate> _avaliableBuildInFunctions = null;

        #endregion

        #region Static Methods

        private static void BuildAvaliableCommands()
        {
            _avaliableCommands = new Dictionary<string, ScriptCommand.ScriptCommandActionDelegate>();

            // add each known command
            _avaliableCommands.Add("loadworld", ScriptCommand_LoadWorld.Action);
            _avaliableCommands.Add("loadcharacter", ScriptCommand_LoadCharacter.Action);
            _avaliableCommands.Add("loadscript", ScriptCommand_LoadScript.Action);
            _avaliableCommands.Add("setscreensize", ScriptCommand_SetScreenSize.Action);
            _avaliableCommands.Add("loadhud", ScriptCommand_LoadHUD.Action);
            _avaliableCommands.Add("addhudcontrol", ScriptCommand_AddHUDControl.Action);
            _avaliableCommands.Add("setsystemvariable", ScriptCommand_SetSystemVariable.Action);
            _avaliableCommands.Add("addevent", ScriptCommand_AddEvent.Action);
            _avaliableCommands.Add("exitgame", ScriptCommand_ExitGame.Action);
            _avaliableCommands.Add("restartgame", ScriptCommand_RestartGame.Action);
            _avaliableCommands.Add("leveltime", ScriptCommand_LevelTime.Action);
            _avaliableCommands.Add("loadmenu", ScriptCommand_LoadMenu.Action);
            _avaliableCommands.Add("setworldfocusedentity", ScriptCommand_SetWorldFocusedEntity.Action);
            _avaliableCommands.Add("declare", ScriptCommand_Declare.Action);
            _avaliableCommands.Add("add", ScriptCommand_Add.Action);
            _avaliableCommands.Add("subtract", ScriptCommand_Subtract.Action);
        }

        private static void BuildAvaliableBuildInFunctions()
        {
            _avaliableBuildInFunctions = new Dictionary<string, ScriptCommand.ScriptBuildInFunctionActionDelegate>();

            // add each known build in function
            _avaliableBuildInFunctions.Add("random", ScriptFunction_Random.Action);
            _avaliableBuildInFunctions.Add("getsystemvariable", ScriptFunction_GetSystemVariable.Action);
        }

        #endregion
    }
}
